package com.xjoyt.pay.master.po;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.ForeignKey;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.GenericGenerator;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.xjoyt.pay.constants.DateConstant;
import com.xjoyt.pay.vo.PayMethod;
import com.xjoyt.pay.vo.PayType;
import com.xjoyt.pay.vo.TradeType;

/**
 * 交易订单
 * 
 * @author Administrator
 *
 */
@Entity
@Table(name = "t_order")
public class Order {

	@Id
	@GeneratedValue(generator = "uuid")
	@GenericGenerator(name = "uuid", strategy = "uuid2")
	@Column(name = "order_id", length = 36)
	public String id;

	/**
	 * 系统流水号
	 */
	@Column(name = "no", length = 50)
	public String no;

	/**
	 * 上游流水号
	 */
	@Column(name = "trade_no", length = 255)
	public String tradeNo;

	/**
	 * 上游商户号
	 */
	@Column(name = "trade_merchant_no", length = 255)
	public String tradeMerchantNo;

	/**
	 * 商户流水号
	 */
	@Column(name = "out_trade_no", length = 255)
	public String outTradeNo;

	/**
	 * 订单内容
	 */
	@Column(name = "`body`", length = 255)
	public String body;

	/**
	 * 订单详情
	 */
	@Column(name = "`detail`", length = 255)
	public String detail;

	/**
	 * 金额(分)
	 */
	@Column(name = "money")
	public Long money;

	/**
	 * 固定手续费(分)
	 */
	@Column(name = "poundage")
	public Long poundage;

	/**
	 * 固定成本手续费(分)
	 */
	@Column(name = "cost_poundage")
	public Long costPoundage;

	/**
	 * 支付通道固定手续费(分)
	 */
	@Column(name = "channel_poundage")
	public Long channelPoundage;

	/**
	 * 下游通知地址
	 */
	@Column(name = "notify_url", length = 255)
	public String notifyUrl;

	/**
	 * 前台通知地址
	 */
	@Column(name = "success_url", length = 255)
	public String successUrl;

	/**
	 * 支付通道费率(%)
	 */
	@Column(name = "channel_rate")
	public Double channelRate;

	/**
	 * 结算费率(‰)
	 */
	@Column(name = "rate")
	public Double rate;

	/**
	 * 上限手续费(分)
	 */
	@Column(name = "`limit`")
	public Long limit;

	/**
	 * 上限成本手续费(分)
	 */
	@Column(name = "cost_limit")
	public Long costLimit;

	/**
	 * 支付通道上限手续费(分)
	 */
	@Column(name = "channel_limit")
	public Long channelLimit;

	/**
	 * 下限手续费(分)
	 */
	@Column(name = "`minimum`")
	public Long minimum;

	/**
	 * 下限成本手续费(分)
	 */
	@Column(name = "`cost_minimum`")
	public Long costMinimum;

	/**
	 * 支付通道下限手续费(分)
	 */
	@Column(name = "channel_minimum")
	public Long channelMinimum;

	/**
	 * 支付类型(如：微信，支付宝)
	 */
	@Column(name = "pay_type", length = 20)
	@Enumerated(EnumType.STRING)
	public PayType payType;

	/**
	 * 支付方式(如：银联扫码，银联条码)
	 */
	@Column(name = "pay_method", length = 50)
	@Enumerated(EnumType.STRING)
	public PayMethod payMethod;

	/**
	 * 授权码
	 */
	@Column(name = "auth_code", length = 50)
	public String authCode;

	/**
	 * 结算类型(如T0、T1)
	 */
	@Column(name = "trade_type", length = 20)
	@Enumerated(EnumType.STRING)
	public TradeType tradeType;

	/**
	 * 商户
	 * order中不应保存商户信息.调用接口保存商户信息.
	 */
	@ManyToOne(targetEntity = Merchant.class, cascade = {})
	@JoinColumn(name = "merchant_id", foreignKey = @ForeignKey(name = "none"))
	// @JsonIgnore
	public Merchant merchant;

	@JoinColumn(name = "merchant_id", foreignKey = @ForeignKey(name = "none"))
	// @JsonIgnore
	public String merchatId;
	
	/**
	 * 商户名称
	 */
	@Column(name = "merchant_name", length = 50)
	public String merchantName;

	/**
	 * 商户号
	 */
	@Column(name = "merchant_no", length = 50)
	public String merchantNo;

	/**
	 * 产品ID
	 */
	@Column(name = "product_id", length = 50)
	public String productId;

	/**
	 * 订单配置
	 */
	@OneToOne(mappedBy = "order")
	public OrderConfig orderConfig;

	/**
	 * 下单状态(NULL：未生成订单，true：订单生成成功，false：订单生成失败)
	 */
	@org.hibernate.annotations.Type(type = "yes_no")
	@Column(name = "is_success")
	public Boolean success;

	/**
	 * 下单日期
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "added_date")
	@JsonFormat(pattern = DateConstant.DATE_TIME_FORMAT_PATTERN, timezone = "GMT+8")
	public Date addedDate;

	/**
	 * 是否付款(true：付款成功，false：未付款)
	 */
	@org.hibernate.annotations.Type(type = "yes_no")
	@Column(name = "is_done")
	public Boolean done;

	/**
	 * 付款日期
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "done_date")
	@JsonFormat(pattern = DateConstant.DATE_TIME_FORMAT_PATTERN, timezone = "GMT+8")
	public Date doneDate;

	/**
	 * 是否通知下游(NULL：未通知单，true：通知成功，false：通知失败)
	 */
	@org.hibernate.annotations.Type(type = "yes_no")
	@Column(name = "is_notify")
	public Boolean notify;

	/**
	 * 通知日期
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "notify_date")
	@JsonFormat(pattern = DateConstant.DATE_TIME_FORMAT_PATTERN, timezone = "GMT+8")
	public Date notifyDate;

	/**
	 * 结算状态(NULL：结算中，true：已结算，false：未结算)
	 */
	@org.hibernate.annotations.Type(type = "yes_no")
	@Column(name = "is_pay")
	public Boolean pay;

	/**
	 * 结算日期
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "pay_date")
	@JsonFormat(pattern = DateConstant.DATE_TIME_FORMAT_PATTERN, timezone = "GMT+8")
	public Date payDate;

	/**
	 * 是否对账(true：已对账，false：未对账)
	 */
	@org.hibernate.annotations.Type(type = "yes_no")
	@Column(name = "is_check")
	public Boolean check;

	/**
	 * 是否提现(true：已对账，false：未对账)
	 */
	@org.hibernate.annotations.Type(type = "yes_no")
	@Column(name = "has_cash")
	public Boolean hasCash;

	/**
	 * 对账日期
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "check_date")
	@JsonFormat(pattern = DateConstant.DATE_TIME_FORMAT_PATTERN, timezone = "GMT+8")
	public Date checkDate;

	/**
	 * 对账金额(分)
	 */
	@Column(name = "check_money")
	public Long checkMoney;

	/**
	 * 对账类型(0：自动，1：手动)
	 */
	@Column(name = "check_type")
	public Integer checkType;

	/**
	 * 退款状态(true：已状态，false：未状态)
	 */
	@org.hibernate.annotations.Type(type = "yes_no")
	@Column(name = "is_back")
	public Boolean back;

	/**
	 * 退款日期
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "back_date")
	@JsonFormat(pattern = DateConstant.DATE_TIME_FORMAT_PATTERN, timezone = "GMT+8")
	public Date backDate;

}
